﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Algorithm_2.Easy_349_Intersection
{
    class MainProject
    {
        static void Main(string[] args)
        {
            int[] intArray1 = new int[] { 4,9,5};
            int[] intArray2 = new int[] { 9,4,9,8,4 };
            foreach (var item in Intersection(intArray1, intArray2))
            {
                Console.WriteLine(item);
            }
            Console.ReadKey();
        }

        public static int[] Intersection(int[] nums1, int[] nums2)
        {
            HashSet<int> list = new HashSet<int>();
            int[] targetArray = null;
            int[] anthorArray = null;
            targetArray = nums1.Length > nums2.Length ? nums1 : nums2;
            anthorArray = nums1.Length > nums2.Length ? nums2 : nums1;

            foreach (var item in targetArray)
            {
                foreach (var item1 in anthorArray)
                {
                    if (item == item1)
                    {
                        list.Add(item);
                        break;
                    }
                }
            }
            return list.ToArray();
        }
    }
}
